const mysql = require("mysql");
class MysqlPool {
  constructor(ops) {
    this.flag = false;
    this.pool = mysql.createPool({
      ...{
        host: "localhost",
        user: "root",
        password: "123456",
        database: "test",
        port: 3306,
      },
      ...(ops || {}),
    });
    return this;
  }
  getPool() {
    if (!this.flag) {
      this.flag = true;
      this.pool.on("connection", (conn) => {
        conn.query("SET SESSION auto_increment_increment = 1");
        this.flag = false;
      });
    }
    return this.pool;
  }
}

module.exports = MysqlPool;
